/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MenuPrincipal;

import Bkup.BackUp;
import apunte.Apunte;
import crear.cargarApunte;
import crear.crearProfesor;
import crear.crearCarrera;
import crear.crearMateria;
import eliminar.*;
import inicio.arranca;
import inicio.inicio;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.JRException;

import reportes.IReportClass;
import usuarios.Editar;
import usuarios.Vendedor;
import usuarios.crearVendedor;
/**
 *
 * @author martinLequerica
 */
public class listeners {
    
    public listeners(LinkedList<JMenuItem> lba,LinkedList<JMenuItem> lbe,LinkedList<JMenuItem> lbm,final Vendedor v,
            final MenuPrincipal mp,LinkedList<JMenuItem> lbb,final LinkedList<Apunte> lla,LinkedList<JMenuItem> lbar){

        
  
        
        //apunte
            //agregar
        lba.get(0).addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                try {
                    new cargarApunte();
                } catch (SQLException ex) {
                    Logger.getLogger(listeners.class.getName()).log(Level.SEVERE, null, ex);
                }
                
                
            }
        });
            //eliminar
        lbe.get(0).addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                try {
                    new eliminarApunte();
                } catch (SQLException ex) {
                    Logger.getLogger(listeners.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
        
        //materia
            //agregar
        lba.get(1).addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
           
                new crearMateria();
            }
        });
        
            //eliminar
        lbe.get(1).addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                try {
                    new eliminarMateria();
                } catch (SQLException ex) {
                    Logger.getLogger(listeners.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
        
        //profesor
            //agregar
        lba.get(2).addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
           new crearProfesor();
                
            }
        });
        
            //eliminar
        lbe.get(2).addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                try {
                    new eliminarProfesor();
                } catch (SQLException ex) {
                    Logger.getLogger(listeners.class.getName()).log(Level.SEVERE, null, ex);
                }
                
                
            }
        });
        //carrera
            //agregar
        lba.get(3).addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                new crearCarrera();
            }
        });
        //eliminar
        lbe.get(3).addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                try {
                    new eliminarCarrera();
                } catch (SQLException ex) {
                    Logger.getLogger(listeners.class.getName()).log(Level.SEVERE, null, ex);
                }
                
            }
        });
        
        //modificar usuario
        lbm.get(0).addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
           
                new Editar(v);
                
            }
        });
        //agregar usuario
        lbm.get(1).addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                
                if (v.getNombreUsuario().equals("fotocopiadora")){
                
                new crearVendedor("si");
                }else {
                    
                    JOptionPane.showMessageDialog(null, "Solo el usuario Fotocopiadora puede crear nuevos usuarios.");
                    
                }
            }
        });
        //cambiar de usuario
        lbm.get(2).addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
               
              mp.setVisible(false);
                
                try {
                    new arranca();
                } catch (SQLException ex) {
                    Logger.getLogger(listeners.class.getName()).log(Level.SEVERE, null, ex);
                }
               
               
                
                
            }
        });
        
        //bkup
            //crear  bkup
            
        //crear back up
            lbb.get(0).addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                try {
                    new BackUp().crearBkup(lla);
                } catch (IOException ex) {
                    Logger.getLogger(listeners.class.getName()).log(Level.SEVERE, null, ex);
                }
                
            }
        });
            
            //recuperar bkup
            
            lbb.get(1).addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                try {
                    try {
                        new BackUp().recuperarBkup();
                    } catch (SQLException ex) {
                        Logger.getLogger(listeners.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } catch (IOException ex) {
                    Logger.getLogger(listeners.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(listeners.class.getName()).log(Level.SEVERE, null, ex);
                }
                
                
            }
        });
        
    
            
            //botones archivo
            
            lbar.get(0).addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
            
                    new IReportClass().finDeTurno(v);
                    
                
                
            }
        });
                    
            
            
            
            //cerrar turno
            lbar.get(1).addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                try {
                    new IReportClass().crearReporte();
                    
                } catch (JRException ex) {
                    Logger.getLogger(listeners.class.getName()).log(Level.SEVERE, null, ex);
                }
                
                
                
                
                
            }
        });
       
        
    }




    
    
}
